﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class Index2 : System.Web.UI.Page
{
    security baomat = new security();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            TopBrand();
            TopSearchBusiness();
        }
    }

    private void TopBrand()
    {
        try
        {
            StringBuilder sb = new StringBuilder();
            using (Up1VNDataContext dc = new Up1VNDataContext())
            {
                var ListTopBusiness = (from o in dc.EStores select o).ToList();
                if (ListTopBusiness.Count > 0)
                {
                    //sb.Append("<ul>");
                    foreach (var item in ListTopBusiness)
                    {
                        string logo = (item.EStore_Logo != null) ? ResolveUrl("~/User/avatar/" + item.EStore_Logo) : ResolveUrl("~/images/box.jpg");
                        sb.Append("<li>");
                        sb.AppendFormat("<a href='{0}' class='thumb_brand'>", ResolveUrl("~/" + baomat.RemoveSpecialCharacter(item.EStore_Name).Replace(" ", "-").ToLower() + "/Thongtindoanhnghiep.html"));
                        sb.AppendFormat("<img src='{0}' alt='{1}' title='{2}' />", logo, item.EStore_Name, item.EStore_Name);
                        sb.AppendFormat("<span class='fade_info'>{0}</span></a>", item.EStore_Name);
                        sb.Append("</li>");
                    }
                    //sb.Append("</ul>");
                    ltrTopBusiness.Text = sb.ToString();
                }
            }
        }
        catch
        {
        }
    }

    private void TopSearchBusiness()
    {
        try
        {
            using (Up1VNDataContext dc = new Up1VNDataContext())
            {
                var Topview = (from o in dc.EStores
                               join u in dc.Users on o.Users_Id equals u.Users_Id
                               orderby o.EStore_View
                               select new
                               {
                                   o.EStore_MobilePhone,
                                   o.EStore_Id,
                                   o.EStore_Name,
                                   o.Estore_HomePhone,
                                   o.EStore_Logo,
                                   o.EStore_Website,
                                   u.Users_Email
                               }).Take(18).ToList();
                if (Topview.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var item in Topview)
                    {
                        string logo = (item.EStore_Logo != null) ? ResolveUrl("~/User/avatar/" + item.EStore_Logo) : ResolveUrl("~/images/logo_box.jpg");
                        string path = ResolveUrl("~/" + baomat.RemoveSpecialCharacter(item.EStore_Name).Replace(" ", "-").ToLower() + "/Thongtindoanhnghiep.html");
                        sb.AppendFormat("<li><h2 class='brand_title'><a href='{0}'>{1}</a></h2>", path, item.EStore_Name);
                        sb.AppendFormat("<a class='thumb_brand' href='{0}'><img src='{1}' alt='{2}' title='{3}' /></a>", path, logo, item.EStore_Name, item.EStore_Name);
                        sb.AppendFormat("<p class='brand_quote'>[P] {0}<br />[M] {1}<br />[E] {2}</p>", item.Estore_HomePhone, item.EStore_MobilePhone, item.Users_Email);
                        sb.AppendFormat("<a href='{0}' class='brand_link'>{1}</a><div class='clear'></div></li>", path, item.EStore_Website);
                    }
                    ltrTopsearch.Text = sb.ToString();
                }
            }
        }
        catch (Exception ex)
        {
        }
    }
}